package com.fyzk.activity.lottery.jc.beidan;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tyjc.lottery.R;

import java.util.List;

/**
 * Created by fanxs11 on 2017/11/22.
 */

public class BeiDan_BQC_PayAdapter extends BeiDanBasePayAdapter {

    public BeiDan_BQC_PayAdapter(Context context, List<BeiDanChildBean> infors, OnBeiDanPayClickListerner listerner) {
        super(context, infors, listerner);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final BeiDanChildBean info = infors.get(i);
        ViewHolder holder = null;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.adapter_beidan_bqc_pay, null);
            holder.zhu = view.findViewById(R.id.beidan_pay_list_item_zhu);
            holder.delete = view.findViewById(R.id.beidan_pay_list_item_delete);
            holder.home = view.findViewById(R.id.beidan_pay_list_item_home);
            holder.vs = view.findViewById(R.id.beidan_pay_list_item_vs);
            holder.away = view.findViewById(R.id.beidan_pay_list_item_away);
            holder.week_num = view.findViewById(R.id.beidan_pay_list_matchnum);
            holder.bqc_ss = view.findViewById(R.id.beidan_pay_list_item_bqc_ss);
            holder.bqc_sp = view.findViewById(R.id.beidan_pay_list_item_bqc_sp);
            holder.bqc_sf = view.findViewById(R.id.beidan_pay_list_item_bqc_sf);
            holder.bqc_ps = view.findViewById(R.id.beidan_pay_list_item_bqc_ps);
            holder.bqc_pp = view.findViewById(R.id.beidan_pay_list_item_bqc_pp);
            holder.bqc_pf = view.findViewById(R.id.beidan_pay_list_item_bqc_pf);
            holder.bqc_fs = view.findViewById(R.id.beidan_pay_list_item_bqc_fs);
            holder.bqc_fp = view.findViewById(R.id.beidan_pay_list_item_bqc_fp);
            holder.bqc_ff = view.findViewById(R.id.beidan_pay_list_item_bqc_ff);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.week_num.setText(info.getMatchNum()+"");
        holder.home.setText(info.getHomeTeam());
        holder.away.setText(info.getAwayTeam());

        holder.bqc_ss.setText("胜-胜\n"+info.getBqc_33());
        holder.bqc_sp.setText("胜-平\n"+info.getBqc_31());
        holder.bqc_sf.setText("胜-负\n"+info.getBqc_30());
        holder.bqc_ps.setText("平-胜\n"+info.getBqc_13());
        holder.bqc_pp.setText("平-平\n"+info.getBqc_11());
        holder.bqc_pf.setText("平-负\n"+info.getBqc_10());
        holder.bqc_fs.setText("负-胜\n"+info.getBqc_03());
        holder.bqc_fp.setText("负-平\n"+info.getBqc_01());
        holder.bqc_ff.setText("负-负\n"+info.getBqc_00());

        holder.bqc_ss.setChecked(info.isBqc_33);
        holder.bqc_sp.setChecked(info.isBqc_31);
        holder.bqc_sf.setChecked(info.isBqc_30);
        holder.bqc_ps.setChecked(info.isBqc_13);
        holder.bqc_pp.setChecked(info.isBqc_11);
        holder.bqc_pf.setChecked(info.isBqc_10);
        holder.bqc_fs.setChecked(info.isBqc_03);
        holder.bqc_fp.setChecked(info.isBqc_01);
        holder.bqc_ff.setChecked(info.isBqc_00);

        info.btnHGPojo.get(info.BQC_33).isSel = info.isBqc_33;
        info.btnHGPojo.get(info.BQC_31).isSel = info.isBqc_31;
        info.btnHGPojo.get(info.BQC_30).isSel = info.isBqc_30;
        info.btnHGPojo.get(info.BQC_13).isSel = info.isBqc_13;
        info.btnHGPojo.get(info.BQC_11).isSel = info.isBqc_11;
        info.btnHGPojo.get(info.BQC_10).isSel = info.isBqc_10;
        info.btnHGPojo.get(info.BQC_03).isSel = info.isBqc_03;
        info.btnHGPojo.get(info.BQC_01).isSel = info.isBqc_01;
        info.btnHGPojo.get(info.BQC_00).isSel = info.isBqc_00;

        info.btnHGPojo.put(info.BQC_33,info.btnHGPojo.get(info.BQC_33));
        info.btnHGPojo.put(info.BQC_31,info.btnHGPojo.get(info.BQC_31));
        info.btnHGPojo.put(info.BQC_30,info.btnHGPojo.get(info.BQC_30));
        info.btnHGPojo.put(info.BQC_13,info.btnHGPojo.get(info.BQC_13));
        info.btnHGPojo.put(info.BQC_11,info.btnHGPojo.get(info.BQC_11));
        info.btnHGPojo.put(info.BQC_10,info.btnHGPojo.get(info.BQC_10));
        info.btnHGPojo.put(info.BQC_03,info.btnHGPojo.get(info.BQC_03));
        info.btnHGPojo.put(info.BQC_01,info.btnHGPojo.get(info.BQC_01));
        info.btnHGPojo.put(info.BQC_00,info.btnHGPojo.get(info.BQC_00));
        jiSuanZhuShu();

        holder.bqc_ss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isBqc_33 = !info.isBqc_33;
                if (info.isBqc_33) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.bqc_sp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isBqc_31 = !info.isBqc_31;
                if (info.isBqc_31) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.bqc_sf.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isBqc_30 = !info.isBqc_30;
                if (info.isBqc_30) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.bqc_ps.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isBqc_13 = !info.isBqc_13;
                if (info.isBqc_13) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.bqc_pp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isBqc_11 = !info.isBqc_11;
                if (info.isBqc_11) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.bqc_pf.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isBqc_10 = !info.isBqc_10;
                if (info.isBqc_10) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.bqc_fs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isBqc_03 = !info.isBqc_03;
                if (info.isBqc_03) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.bqc_fp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isBqc_01 = !info.isBqc_01;
                if (info.isBqc_01) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.bqc_ff.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isBqc_00 = !info.isBqc_00;
                if (info.isBqc_00) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.clearAll();
                infors.remove(info);
                notifyDataSetChanged();
                if (infors.size() == 0) {
                    jiSuanZhuShu();
                }
            }
        });

        return view;
    }

    @Override
    protected void jiSuanZhuShu() {

        if (listerner != null) {
            listerner.onItemClick();
        }
    }

    class ViewHolder {
        LinearLayout zhu;
        LinearLayout delete;
        TextView home;
        TextView week_num;
        TextView vs;
        TextView away;
        CheckBox bqc_ss;
        CheckBox bqc_sp;
        CheckBox bqc_sf;
        CheckBox bqc_ps;
        CheckBox bqc_pp;
        CheckBox bqc_pf;
        CheckBox bqc_fs;
        CheckBox bqc_fp;
        CheckBox bqc_ff;

    }
}
